﻿package mortal.game.net.command.player
{
    import Framework.MQ.*;
    import Message.Command.*;
    import Message.Public.*;
    import __AS3__.vec.*;
    import flash.geom.*;
    import mortal.game.cache.*;
    import mortal.game.mvc.*;
    import mortal.game.net.broadCast.*;
    import mortal.game.resource.*;
    import mortal.game.scene3D.display3d.text3d.staticText3d.*;
    import mortal.game.scene3D.display3d.text3d.staticText3d.action.*;
    import mortal.game.scene3D.player.entity.*;
    import mortal.mvc.core.*;

    public class FightAttributeCommand extends BroadCastCall
    {
        private var _templeVector:Vector3D;

        public function FightAttributeCommand(param1:Object)
        {
            this._templeVector = new Vector3D();
            super(param1);
            return;
        }// end function

        override public function call(param1:MessageBlock) : void
        {
            var _loc_2:SExtraFightAttribute = null;
            var _loc_3:SSFightAttribute = null;
            var _loc_4:SAllFightAttribute = null;
            switch(param1.messageHead.command)
            {
                case EPublicCommand._ECmdPublicFightAttributeExtra:
                {
                    _loc_2 = param1.messageBase as SExtraFightAttribute;
                    if (_loc_2.uid)
                    {
                        Cache.instance.pet.buffPetUid = "";
                        Cache.instance.pet.updatePetFightAttribute(_loc_2);
                        NetDispatcher.dispatchCmd(ServerCommand.PetAttributeUpdate, _loc_2.uid);
                    }
                    else
                    {
                        this.processSceneAttribute(_loc_2.extraFightAttribute, _cache.role.fightAttributeExt);
                        _cache.role.fightAttributeExt = _loc_2.extraFightAttribute;
                        NetDispatcher.dispatchCmd(ServerCommand.RoleFightAttributeBaseExChange, _loc_2);
                    }
                    break;
                }
                case EPublicCommand._ECmdPublicFightAttribute:
                {
                    _loc_3 = param1.messageBase as SSFightAttribute;
                    if (_loc_3.updateCode == 119)
                    {
                        this.processSceneAttribute(_loc_3.cellFight, _cache.role.fightAttribute);
                    }
                    _cache.role.fightAttribute = _loc_3.cellFight;
                    _cache.role.roleEntityInfo.updateMaxLife(_loc_3.cellFight.maxLife);
                    _cache.role.roleEntityInfo.updateMaxMana(_loc_3.cellFight.maxMana);
                    _cache.role.roleEntityInfo.updateSpeed(_loc_3.cellFight.speed);
                    NetDispatcher.dispatchCmd(ServerCommand.RoleFightAttributeChange, _cache.role.fightAttribute);
                    break;
                }
                case EPublicCommand._ECmdPublicFightAttributeAll:
                {
                    _loc_4 = param1.messageBase as SAllFightAttribute;
                    if (_loc_4.uid)
                    {
                        Cache.instance.pet.updateAllFightAttribute(_loc_4);
                        NetDispatcher.dispatchCmd(ServerCommand.PetAttributeUpdate, _loc_4.uid);
                    }
                    else
                    {
                        this.processSceneAttribute(_loc_4.baseFight, _cache.role.fightAttributeBase);
                        _cache.role.fightAttributeBase = _loc_4.baseFight;
                        _cache.role.fightAttributeExt = _loc_4.extraFightAttribute;
                    }
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        private function processSceneAttribute(param1:SFightAttribute, param2:SFightAttribute) : void
        {
            var _loc_3:Array = null;
            var _loc_4:Vector.<String> = null;
            var _loc_5:String = null;
            var _loc_6:Boolean = false;
            var _loc_7:ActionVo = null;
            var _loc_8:int = 0;
            var _loc_9:int = 0;
            var _loc_10:String = null;
            if (param2)
            {
                _loc_3 = ["hit", "crit", "expertise", "jouk", "physDefense", "magicDefense", "penetration", "attack", "maxLife", "block", "toughness"];
                _loc_4 = this.Vector.<String>(_loc_3);
                _loc_6 = RolePlayer.hasInstacne() && RolePlayer.instance.bodyPlayer;
                if (!_loc_6)
                {
                    return;
                }
                _loc_7 = new ActionVo();
                _loc_7.reInit(2, 0, 0, 0, 0, false, false);
                _loc_8 = 0;
                while (_loc_8 < _loc_4.length)
                {
                    
                    _loc_5 = _loc_4[_loc_8];
                    if (param1[_loc_5] != param2[_loc_5])
                    {
                        _loc_9 = int(param1[_loc_5]) - int(param2[_loc_5]);
                        if (_loc_9 <= 0)
                        {
                            break;
                        }
                        _loc_10 = GameDefConfig.instance.getFightAttributeName(_loc_5) + "+" + _loc_9;
                        SText3DFactory.instance.createtext3D(_loc_10, 0, RolePlayer.instance.bodyPlayer, _loc_7);
                    }
                    _loc_8++;
                }
            }
            return;
        }// end function

    }
}
